package com.sc.nft.dao;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.dto.ActivityTaskPlanAdminDTO;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.mapper.ActivityTaskPlanMapper;
import com.sc.nft.entity.ActivityTaskPlan;
import com.sc.nft.service.ActivityTaskPlanService;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (ActivityTaskPlan)表Dao层
 *
 * @author 王伟成
 * @since 2023-09-15 16:05:20
 */
@Slf4j
@Repository
public class ActivityTaskPlanDao extends ServiceImpl<ActivityTaskPlanMapper, ActivityTaskPlan> {

    /**
     * 获取进行中的任务
     * @param taskId
     * @param userId
     * @return
     */
    public ActivityTaskPlan getGoingTask(Long taskId,Long userId){
        LambdaQueryWrapper<ActivityTaskPlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityTaskPlan::getActivityTaskId,taskId);
        wrapper.eq(ActivityTaskPlan::getUserId,userId);
        wrapper.eq(ActivityTaskPlan::getStatus,false);
        wrapper.gt(ActivityTaskPlan::getTaskResetTime, DateTime.now());
        return getOne(wrapper);
    }


    public int getFinishCount(Long taskId,Long userId){
        LambdaQueryWrapper<ActivityTaskPlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActivityTaskPlan::getActivityTaskId,taskId);
        wrapper.eq(ActivityTaskPlan::getUserId,userId);
        wrapper.eq(ActivityTaskPlan::getStatus,true);
        return count(wrapper);
    }

    public Page<ActivityTaskPlan> taskRecord(Page page, Long userId, Long activityId) {
        return baseMapper.taskRecord(page,userId,activityId);
    }

    public Page<ActivityTaskPlanAdminDTO> adminTaskRecord(Page page, Long userId, Long activityId, String taskName) {
        return baseMapper.adminTaskRecord(page, userId, activityId, taskName);
    }
}
